# Maintainer: Balló György <ballogyor+arch at gmail dot com>

pkgname=openbve
_pkgname=OpenBVE
pkgver=1.9.0.3
pkgrel=1
pkgdesc="Free-as-in-freedom train simulator placed in the public domain"
arch=(any)
url="https://openbve-project.net/"
license=(MIT 'custom:public domain')
depends=(hicolor-icon-theme libxi mono openal)
makedepends=(mono-msbuild nuget)
source=(https://github.com/leezer3/$_pkgname/archive/$pkgver/$_pkgname-$pkgver.tar.gz
        $pkgname.sh
        $pkgname.appdata.xml)
sha256sums=('325ccef6fb0eb0d48d750ae8619b3c64fad8cfc951cbb67b489ed47509146cf5'
            'cf0f2a28e65248f742d6bb80f3101e36f24097e699c4e5acdf3fd4dbb965d3c3'
            '1ae1d4bf4dbe0d4e012fafef090d98b4c67ba87bee8981af0b2de11015b57df2')

prepare() {
  cd $_pkgname-$pkgver
  nuget restore OpenBVE.sln
}

build() {
  cd $_pkgname-$pkgver
  msbuild /p:Configuration=Release OpenBVE.sln
}

package() {
  cd $_pkgname-$pkgver

  # Binaries
  install -dm755 "$pkgdir/usr/lib/$pkgname/"
  cp -r bin_release/* "$pkgdir/usr/lib/$pkgname/"

  # Data
  install -dm755 "$pkgdir/usr/share/games/$pkgname/"
  mv "$pkgdir/usr/lib/$pkgname/Data" "$pkgdir/usr/share/games/$pkgname/"
  ln -s ../../share/games/$pkgname/Data "$pkgdir/usr/lib/$pkgname/Data"

  # Executable
  install -Dm755 ../$pkgname.sh "$pkgdir/usr/bin/$pkgname"

  # Desktop file and icon
  install -Dm644 debian/$pkgname.png "$pkgdir/usr/share/icons/hicolor/128x128/apps/$pkgname.png"
  install -Dm644 debian/$pkgname.desktop "$pkgdir/usr/share/applications/$pkgname.desktop"
  install -Dm644 ../$pkgname.appdata.xml "$pkgdir/usr/share/metainfo/$pkgname.appdata.xml"

  # License
  install -dm755 "$pkgdir/usr/share/licenses/$pkgname/"
  install -m644 licenses/* Readme.md \
    "$pkgdir/usr/share/licenses/$pkgname/"
}
